thispage=1;
totalpages=0;

$(".form-date").datetimepicker(
    {
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0,
        format: "yyyy-mm-dd"
    });
// 选择时间和日期
$(".form-datetime").datetimepicker(
    {
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        format: "yyyy-mm-dd hh:ii"
    });
//ajks

function worktypeshow(thispage){
    $.ajax({
        url:"c/WorkTypeControl/show",
        type:"post",
        dataType:"json",
        data:{
            thispage:thispage
        },
        success:function (data){

            workerSelct1(data);
        },
        error:function (err){
            console.log("错误");
        }
    })
}

util(thispage);
worktypeshow(thispage);
function datashow(name,state,begin,end,thispage){
    $.ajax({
        url:"c/corderShowControl/show",
        dataType:"json",
        type:"POST",
        data:{
            name:name,
            state:state,
            begin:begin,
            end:end,
            thispage:thispage
        },
        success:function (data){

            buordershow(data);
        },
        error:function (err){
            console.log("数据错误");
        },
    });
}
//删除
function datadel(seq){
    $.ajax({
        url:"c/cordelShowControl/delete",
        dataType:"json",
        type:"POST",
        data:{
        seq:seq,
        },
        success:function (data){

            util(thispage);
        },
        error:function (err){
            console.log("数据错误");
        },
    });
}
//修改
function up1(seq,num,location,begin,end,workerid,money){
    $.ajax({
        url:"c/ccjordelShowControl/update",
        dataType:"json",
        type:"POST",
        data:{
            seq:seq,
            num:num,
            location:location,
            begin:begin,
            end:end,
            workerid:workerid,
            money:money,
        },
        success:function (data){

            util(thispage);
        },
        error:function (err){
            console.log("数据错误");
        },
    });
}
//ajks相应
function  buordershow(data){
    str='';
    tbody =document.getElementById("user-table");
    for (var i=0;i<data.list.length;i++){
        let a=data.list[i];
        str +=`
        <tr>
        <td>${a.buSeq}</td>
        <td>${a.buBusinessname}</td>
        <td>${a.number}</td>
         <td>${a.joblocation}</td>
         <td>${a.salary}</td>
        <td>${a.wtName}</td>
        <td>${a.begin}</td>
        <td>${a.end}</td>
        <td>${a.stateName}</td>
        <td>
           <button class="btn btn-primary btn-sm" onclick="buOrderupdate(this)" id="${a.recruitmen}">编辑</button>
           <button class="btn btn-danger btn-sm" onclick="backdelete(this)">删除</button>
        </td>
        </tr>
    `
        totalpages=(data.pages*5);
        var myPager = $('#myPager').data('zui.pager');
        myPager.set({
            page: thispage,
            recTotal: totalpages,
            recPerPage: 5
        });
    }

       tbody.innerHTML=str;
}

function workerSelct1(data){
    select=document.getElementById("workertype");
    str ='';
    for (var i=0 ;i<data.list.length;i++){
        str +=`
        <option id="${data.list[i].wtId}">${data.list[i].wtName}</option>
        `
    }
     select.innerHTML=str;
}


//按钮响应区
function buOrderupdate(ihk){
    var seq=ihk.parentNode.parentNode.children[0].innerHTML;
    var num=ihk.parentNode.parentNode.children[2].innerHTML;
    var location=ihk.parentNode.parentNode.children[3].innerHTML;
    var money=ihk.parentNode.parentNode.children[4].innerHTML;
    document.getElementById("WorkerNum").value=num;
    document.getElementById("location").value=location;
    document.getElementById("money").value=money;
    document.getElementById("ccjyesid").value=money;
    $('#edictccj').modal('toggle', 'center')

}

function edictbj(){
    var end=document.getElementById("money").value;

    var location =document.getElementById("location").value;

    var begin=document.getElementById("begindate").value;

    var end=document.getElementById("enddate").value;

    var kd1 = document.getElementById('workertype');
    var d1 = kd1.selectedIndex;
    var workertype = kd1.options[d1].id;

    var num=document.getElementById("WorkerNum").value;

    var seq=document.getElementById("ccjyesid").value;

    var money=document.getElementById("money").value;

    up1(seq,num,location,begin,end,workertype,money);
}
function backdelete(ink){
    var seq=ihk.parentNode.parentNode.children[0].innerHTML;
    datadel(seq);
}
//util类
function util(){
    var name =document.getElementById("user-name").value;
    var state=document.getElementById("gr-select").value;
    var begin=document.getElementById("selectbegin").value;
    var end=document.getElementById("selectend").value;
    if(end<begin){
        alert("你选择的日期开始时间大于结束时间")
    }else{
        datashow(name,state,begin,end,thispage);
    }
}

// 分页
$('#myPager').on('onPageChange', function(e, state, oldState) {
    if (state.page !== oldState.page) {


        thispage=state.page;
        util(state.page);
    }
});